package or.exa.cangguan.service.impl;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import or.exa.cangguan.common.Page;
import or.exa.cangguan.entity.dto.GoodsPlaceDto;
import or.exa.cangguan.entity.vo.GoodsPlaceVo;
import or.exa.cangguan.mapper.GoodsMapper;
import or.exa.cangguan.mapper.GoodsPlaceMapper;
import or.exa.cangguan.mapper.StoreMapper;
import or.exa.cangguan.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class StockServiceImpl implements StockService {
    @Autowired
    private GoodsPlaceMapper goodsPlaceMapper;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private GoodsMapper goodsMapper;


    @Override
    public Page getStockList(GoodsPlaceVo goodsPlaceVo) {
        Integer storeId = null;

        Integer goodsId = null;
        log.info("-------------------"+goodsPlaceVo);
        Page page = new Page();
        BeanUtil.copyProperties(goodsPlaceVo, page);
        if (goodsPlaceVo.getStoreName() != null && goodsPlaceVo.getStoreName()!="") {
             storeId = storeMapper.selectByName(goodsPlaceVo.getStoreName());

        }
        if (goodsPlaceVo.getGoodsName() != null && goodsPlaceVo.getGoodsName()!="") {
             goodsId = goodsMapper.selectIdByName(goodsPlaceVo.getGoodsName());
        }
        goodsPlaceVo.setStoreId(storeId);
        goodsPlaceVo.setGoodsId(goodsId);

        List<GoodsPlaceDto> goodsPlaceDtos = goodsPlaceMapper.selectAll(goodsPlaceVo,page);
        page.setResultList(goodsPlaceDtos);
        Integer totalNum = goodsPlaceMapper.selectAllCount(goodsPlaceVo);
        page.setTotalNum(totalNum);

        return  page;
    }
}
